package com.qf.web.controller;

import com.qf.pojo.Lend;
import com.qf.service.LendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@Slf4j
@RequestMapping("/lend")
public class LendController {
    @Autowired
    private LendService lendService;

    /**
     * 查询借出/归还情况
     * @return
     */
    @GetMapping("/list")
    public ModelAndView list(){
        log.info("lendOrBackController list ......");
        List<Lend> lends =lendService.findAll();
        ModelAndView modelAndView = new ModelAndView("lend-list");
        modelAndView.addObject("list",lends);
        return modelAndView;
    }

    /**
     * 删除书籍
     * @param serNum
     * @return
     */
    @GetMapping("/deletelend.html")
    public ModelAndView delete(Long serNum){
        log.info("lendOrBackController delete ......");
        lendService.delete(serNum);
        ModelAndView modelAndView = new ModelAndView("redirect:/lend/list");
        modelAndView.addObject("succ","删除成功");
        return modelAndView;
    }

    /**
     * 查询借出/归还情况(借阅方
     * @return
     */
    @GetMapping("/lendlist")
    public ModelAndView lendlist(Long readerId){
        log.info("lendOrBackController lendlist ......");
        List<Lend> lends =lendService.findByReaderId(readerId);
        ModelAndView modelAndView = new ModelAndView("reader-lend");
        modelAndView.addObject("list",lends);
        return modelAndView;
    }
}
